package score;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.NoneScoped;
import javax.faces.event.PhaseId;
import javax.faces.event.ValueChangeEvent;

/**
 *
 * @author Thorsten Ludwig
 */

@ManagedBean(name="scoreCell")
@NoneScoped
public class ScoreCell {
    
    private Score score;
    
    
  
    public ScoreCell(Score score) {
        this.score = score;
    }
    
    public void scoreChanged(ValueChangeEvent v) {
        if (v.getPhaseId().equals(PhaseId.ANY_PHASE)) {
            v.setPhaseId(PhaseId.INVOKE_APPLICATION);
            v.queue();
        } else {
            this.score.setStatus(Status.EDITED);
            this.score.setScore((Double) v.getNewValue());
        }
    }

    public Score getScore() {
        return score;
    }
}